﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using fbasync.webcomponents;
using fbasync.web.Controls;

namespace fbasync.web
{
    public partial class TemplateEditor : Page
    {
        protected void TestSetUserPref_Click(object sender, EventArgs e)
        {
            Global.Connection.SetUserPreferenceCompleted += new EventHandler<AsyncCompletedEventArgs<bool>>(Connection_SetUserPreferenceCompleted);
            Global.Connection.SetUserPreferenceAsync(0, "Test value");
        }

        void Connection_SetUserPreferenceCompleted(object sender, AsyncCompletedEventArgs<bool> e)
        {
            if (null != e.Error) ExceptionHandler.HandleException(e.Error);
            else
                ExceptionHandler.HandleException(new Exception("The value is set"));
                
        }

        protected void TestDefineAss_Click(object sender, EventArgs e)
        {
            Global.Connection.DefineAssociationCompleted += new EventHandler<AsyncCompletedEventArgs<bool>>(Connection_DefineAssCompleted);

            IDictionary<string, string> info1 = new Dictionary<string, string>();
            IDictionary<string, string> info2 = new Dictionary<string, string>();

            info1.Add("alias", "user");
            info2.Add("alias", "category");

            Global.Connection.DefineAssociationAsync("select_category", AssociationTypes.OneWay, info1, info2, null);
        }

        void Connection_DefineAssCompleted(object sender, AsyncCompletedEventArgs<bool> e)
        {
            if (null != e.Error) ExceptionHandler.HandleException(e.Error);
            else
                ExceptionHandler.HandleException(new Exception("The association is defined"));

        }

        protected void TestCreateObjectType_Click(object sender, EventArgs e)
        {
            Global.Connection.CreateObjectTypeCompleted += new EventHandler<AsyncCompletedEventArgs<bool>>(Connection_CreateObjectTypeCompleted);

            Global.Connection.CreateObjectTypeAsync("test_object");
        }

        void Connection_CreateObjectTypeCompleted(object sender, AsyncCompletedEventArgs<bool> e)
        {
            if (null != e.Error) ExceptionHandler.HandleException(e.Error);
            else
                ExceptionHandler.HandleException(new Exception("The type is created"));
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
        }
    }
}
